/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pl.edu.agh.student.logic.validator;

/**
 *
 * @author janburkot
 */
import java.io.Serializable;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.*;

public abstract class PatternValidator implements Validator, Serializable{

    private String regex;
    
    public PatternValidator() {
    }
    
    public PatternValidator(String regex) {
        this.regex = regex;
    }

    public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
        String strValue = (String)value;
        
        System.out.println("PatternValidator");
        System.out.println(strValue);
        System.out.println(regex);
        if (!strValue.matches(regex)){
            throw new ValidatorException(new FacesMessage(regex+" not match"));
        }
    }

    public final void setRegex(final String regex) {
        System.out.println("setRegex(String regex)");
        this.regex = regex;
    }
    
}
